import { integer, time, float } from '../util';

function getRandomTime() {
  return {
    h: time('HH'),
    m: time('mm'),
    s: time('ss'),
  };
}

//服务可用性
function getServerUseable() {
  const len = 60;
  const result = [];
  const t = getRandomTime();
  for (let i = 0; i < len; i++) {
    result.push({
      time: `${t.h}:${+t.m + i}`,
      count: integer(0, 100),
    });
  }
  return result.reverse();
}

//qps
function getQps() {
  const len = 30;
  const result = [];
  const t = getRandomTime();
  for (let i = 0; i < len; i++) {
    result.push({
      time: `${t.h}:${+t.m + i}`,
      count: integer(300, 1000),
    });
  }

  return result;
}

//异常
function getErrors() {
  const len = 30;
  const result = [];
  for (let i = 0; i < len; i++) {
    result.push({
      time: time('HH:mm'),
      '4xx': integer(50, 200),
      '5xx': integer(10, 200),
    });
  }
  return result;
}
//流量
function getFlow() {
  const len = 60;
  const result = [];
  const t = getRandomTime();
  for (let i = 0; i < len; i++) {
    result.push({
      time: `${t.h}:${+t.m + i}`,
      count: integer(100, 2000),
    });
  }

  return result;
}

//应用排名
function getAppRank() {
  const len = 20;
  const result = [];
  let base2xx = integer(1, 200);
  let base3xx = integer(1, 200);
  let base4xx = integer(1, 200);
  let base5xx = integer(1, 200);
  for (let i = 0; i < len; i++) {
    const e2xx = base2xx + integer(1, 100);
    const e3xx = base3xx + integer(1, 100);
    const e4xx = base4xx + integer(1, 100);
    const e5xx = base5xx + integer(1, 100);
    base2xx = e2xx;
    base3xx = e3xx;
    base4xx = e4xx;
    base5xx = e5xx;
    result.push({
      appName: `应用名-${integer(1, 200)}`,
      '2xx': e2xx,
      '3xx': e3xx,
      '4xx': e4xx,
      '5xx': e5xx,
    });
  }
  return result;
}

export default [
  {
    url: '/mock/getDashboardData',
    type: 'get',
    // off: true,
    // proxyUrl: 'http://yapi.int.medlinker.com/mock/279/magic-interface/user/v1/GetUserInfo',
    template: () => {
      return {
        errcode: 0,
        errmsg: '',
        data: {
          appCount: integer(200, 400),
          flowCount: integer(10000, 50000),
          requestCount: integer(100000, 500000),
          serverUseable: getServerUseable(),
          qps: getQps(),
          errors: getErrors(),
          flow: getFlow(),
          appRank: getAppRank(),
        },
      };
    },
  },
];
